package com.jinshan.gaietymall.utils;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * ProjectName:    gaietymall
 * Package:        com.jinshan.gaietymall.utils
 * ClassName:      BasePageResponse
 * Author:     liujinshan
 * Description: 返回list对象 并且包含分页信息
 * Date:    2020/4/15 8:36
 * Version:    1.0
 */
public class BasePageResponseResult<M> {

    /**
     * 返回结果编码
     */
    private String errCode = null;
    /**
     * 返回结果信息
     */
    private String errMsg = null;
    /**
     * 返回数据对象 集合
     */
    private List<M> datas = null;

    private long pageSize;
    private long currentPage;
    private long totalPages;
    private long totalCount;

    public long getPageSize() {
        return pageSize;
    }

    public void setPageSize(long pageSize) {
        this.pageSize = pageSize;
    }

    public long getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(long currentPage) {
        this.currentPage = currentPage;
    }

    public long getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(long totalPages) {
        this.totalPages = totalPages;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(long totalCount) {
        this.totalCount = totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public String getErrCode() {
        return errCode;
    }

    public void setErrCode(String errCode) {
        this.errCode = errCode;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public List<M> getDatas() {
        return datas;
    }

    public void setDatas(List<M> datas) {
        this.datas = datas;
    }

    public BasePageResponseResult() {
    }

    public BasePageResponseResult(String errCode, String errMsg, List<M> datas, long pageSize, long currentPage, long totalPages, long totalCount) {
        this.errCode = errCode;
        this.errMsg = errMsg;
        this.datas = datas;
        this.pageSize = pageSize;
        this.currentPage = currentPage;
        this.totalPages = totalPages;
        this.totalCount = totalCount;
    }

    /**
     * @Author liujinshan
     * @Version  1.0
     * @Description 带数据的OK返回
     * @param page:
     * @Return com.jinshan.gaietymall.utils.BasePageResponseResult
     * @Date 2020/4/15 9:42
     */
    public static BasePageResponseResult ok(IPage<?> page){
        BasePageResponseResult basePageResponseResult = new BasePageResponseResult();
        basePageResponseResult.setDatas(page.getRecords());
        basePageResponseResult.setTotalCount(page.getTotal());
        basePageResponseResult.setPageSize(page.getSize());
        basePageResponseResult.setCurrentPage(page.getCurrent());
        basePageResponseResult.setTotalPages(page.getPages());
        basePageResponseResult.setErrCode("200");
        basePageResponseResult.setErrMsg("执行成功");
        return basePageResponseResult;
    }
    /**
     * @Author liujinshan
     * @Version  1.0
     * @Description 带数据的OK返回
     * @param list:
     * @Return com.jinshan.gaietymall.utils.BasePageResponseResult
     * @Date 2020/4/15 9:42
     */
    public static BasePageResponseResult ok(List<?> list){
        BasePageResponseResult basePageResponseResult = new BasePageResponseResult();
        basePageResponseResult.setDatas(list);
        basePageResponseResult.setErrCode("200");
        basePageResponseResult.setErrMsg("执行成功");
        return basePageResponseResult;
    }
}
